package com.ict.txmsv2.services;

import cn.hutool.core.collection.CollectionUtil;
import com.ict.txmsv2.mapper.LearnResouceMapper;
import com.ict.txmsv2.model.LearnResouce;
import com.ict.txmsv2.model.RespPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yoleen
 * @date 2020/12/16 15:52
 */

@Service
public class LearnResouceService {
    @Autowired
    LearnResouceMapper learnResouceMapper;

    public RespPageBean getLearnResouceList(Integer page, Integer size, LearnResouce learnResource) {
        if(page!=null && page>0){
            page = (page - 1)*size;
        }
        RespPageBean resp = new RespPageBean();
        List<LearnResouce> data = learnResouceMapper.getLearnResouceList(page,size, learnResource);
        resp.setData(data);
        resp.setTotal(learnResouceMapper.getTotal(learnResource));
        return resp;
    }


    public void updateRecord(Integer learnId) {
        learnResouceMapper.updateRecord(learnId);
    }

    public int uploadRecourse(LearnResouce learnResouce) {
        return learnResouceMapper.insertSelective(learnResouce);
    }

    public int deleteRecourse(int id) {
        return learnResouceMapper.deleteByPrimaryKey(id);
    }
}
